#ifndef _ERP_GIS_CORE_AO_DISPATCHER_H_
#define _ERP_GIS_CORE_AO_DISPATCHER_H_

#include "giscoreao_asynprotocol.h"

namespace erp
{
namespace gis
{
namespace ao
{

class CDispatcher
{
	public:
		CDispatcher();
		~CDispatcher();
		template <typename T>
		bool Register(
				const std::string& strParentName,
				const uint32_t dwDefTime,
				const uint32_t dwAlarmThreshold,
				const uint32_t dwCloseThreshold,
				const uint32_t dwCloseDuration,
				const uint32_t dwExtType,
				const bool bOpen,
				const bool bDump)
		{
			m_strLogModule = strParentName;
			CAsynProtocol *pAsynProtocol = new T(strParentName, dwDefTime,dwAlarmThreshold,dwCloseThreshold, dwCloseDuration,dwExtType, bOpen,bDump);
			/*assert(pAsynProtocol);*/
			std::map<uint32_t,erp::gis::ao::CAsynProtocol *>::const_iterator it = m_mapProtocol.find(pAsynProtocol->GetRspCmd());
			if(it == m_mapProtocol.end())
			{
				m_mapProtocol[pAsynProtocol->GetRspCmd()] = pAsynProtocol;
				return true;
			}
			delete pAsynProtocol;
			return false;
		}

		void Destroy();
		uint32_t Dispatch(
			const CCntlInfo& rCntlInfo,
			const std::string& strMachineKey,
			const std::string& strSource,
			uint32_t dwSceneId,
			const uint32_t dwChannel, /*no used currently*/
			const CAsynSendParamBo& oAsynSendParam,
			const std::string& strInReserve,
			CAsynRecvResultBo& oAsynRecvResult,
			erp::gis::ao::CLiber& oLiber) const;
	private:
		uint32_t Clear(
			const CCntlInfo& rCntlInfo,
			const std::string& strMachineKey,
			const std::string& strSource,
			const uint32_t iRetCode,
			const CAsynSendParamBo& oAsynSendParam,
			erp::gis::ao::CLiber& oLiber) const;
	private:
		std::string m_strLogModule;
		std::map<uint32_t,erp::gis::ao::CAsynProtocol *> m_mapProtocol;
};

}
}
}

#endif

